﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

/// <summary>
/// 文本工具类（用于处理一些文本的转换等）
/// 本类针对项目的不同，有不同的内容，放入APP_Code中，以便随时修改
/// </summary>
public class TextUtility
{
    public TextUtility()
    {
    }

    /// <summary>
    /// 设置分页控件的显示文本
    /// </summary>
    /// <param name="PaginateCtl">分页控件</param>
    public static void SetPaginateCtlText(Wuqi.Webdiyer.AspNetPager PaginateCtl)
    {
        PaginateCtl.PageSize = 10;
        PaginateCtl.AlwaysShow = true;
        PaginateCtl.ShowCustomInfoSection = Wuqi.Webdiyer.ShowCustomInfoSection.Right;
        //对齐方式
        PaginateCtl.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
        PaginateCtl.FirstPageText = "首页";
        PaginateCtl.NextPageText = "下一页";
        PaginateCtl.PrevPageText = "上一页";
        PaginateCtl.LastPageText = "尾页";
        PaginateCtl.CustomInfoHTML = "记录总数" + "：<font color=\"blue\"><b> %PageCount% </b></font>";
    }

    /// <summary>
    /// 设置分页控件总记录数
    /// </summary>
    /// <param name="PaginateCtl">分页控件</param>
    public static void SetPaginateCtlRecoText(Wuqi.Webdiyer.AspNetPager PaginateCtl)
    {
        //设置分页控件的总记录数显示文本
        PaginateCtl.CustomInfoHTML = "记录总数" + "：<font color=\"blue\"><b>" + PaginateCtl.RecordCount + "</b></font>";
    }

    /// <summary>
    /// 用于防止简单的查询时的SQL注入
    /// </summary>
    /// <param name="oldStr">原始文本</param>
    /// <returns>替换后的文本</returns>
    public static string ReplaceText(string oldStr)
    {
        //需要被替换的字符
        string[] str_illegal = new string[] { "'" };
        //替换后的字符(索引对应)
        string[] str_legitimate = new string[] { "" };

        string newStr = "";

        for (int i = 0; i < str_illegal.Length; i++)
        {
            newStr = oldStr.Replace(str_illegal[i], str_legitimate[i]);
        }

        return newStr;
    }
}
